﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/jquery.mobile-1.4.2.js" type="text/javascript"></script>
    <link href="css/themes/default/jquery.mobile-1.4.2.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div>
        <input type="text" name="username" id="username" placeholder="帐号" data-clear-btn="true" />
        <input type="password" name="password" id="password" placeholder="密码" data-clear-btn="true" />
    </div>
    <form>
    <label>
        <input id="radio_boy" name="radio-choice-0" checked="true" type="radio">男
    </label>
    <label for="radio_girl">
        女</label>
    <input id="radio_girl" class="custom" name="radio-choice-0" type="radio"></form>
    <div>
        <a data-role="button" id="btnReg" data-theme="b">注册</a>
        <script type="text/javascript">
            $("#btnReg").click(function () {
                var db = window.openDatabase("SugarDB", "1.0", "SugarDB", 5000000);
                db.transaction(queryDB, errorCB, successCB);
            });
            // 查询数据库
            function queryDB(tx) {
                var username = document.getElementById("username").value;
                var password = document.getElementById("password").value;
                var myDate = new Date(); //时间
                var boychecked = document.getElementById("radio_boy").checked;
                var InsertDataTableUserSql = "insert into  LoginInfo (loginName,password,details,createtime,sex) values(?,?,?,?,?)";
                tx.executeSql(InsertDataTableUserSql, [username, password, username, myDate.toLocaleString(), boychecked ? 0 : 1]);
            }
            // 查询成功后调用的回调函数
            function querySuccess(tx, results) {
                if (results.rows.length != 0) {
                    var id = results.rows.item(results.rows.length - 1).id
                    var loginName = results.rows.item(0).loginName
                    alert("查询OK" + id + "登录名" + loginName);
                }
            }
            function errorCB(err) {
                console.log("错误处理的SQL：" + err.code + "错误信息：" + err.message);
                alert("错误信息：" + err.message);

            }
            // 事务执行成功后调用的回调函数
            function successCB() {
                alert("注册成功！");
            }
        </script>
    </div>
</body>
</html>
